package com.cg.bank.web.servlet;

import com.cg.bank.util.JdbcUtils;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;

/**
 * 启动c3p0连接池内部servlet
 *
 * @author chunge
 * @version 1.0
 * @data 2018-0819
 */
public class JdbcUtilsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
    public void init() throws ServletException {
        try {
            // 开启c3p0连接池
            Context context = new InitialContext();
            DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/dataSource");
            JdbcUtils.setDataSource(dataSource);
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
